import { version } from '../package.json'
import CvuBackTop from './component/back-top'
import CvuButton from './component/button'
import CvuButtonGroup from './component/button-group'
import CvuCard from './component/card'
import CvuCol from './component/col'
import CvuCollapse from './component/collapse'
import CvuDivider from './component/divider'
import CvuDrawer from './component/drawer'
import CvuEmpty from './component/empty'
import CvuLayout from './component/layout'
import CvuLoading from './component/loading'
import CvuModal from './component/modal'
import CvuNotification from './component/notification'
import CvuPaginator from './component/paginator'
import CvuPaginatorMini from './component/paginator-mini'
import CvuPoptip from './component/poptip'
import CvuPreview from './component/preview'
import CvuRow from './component/row'
import CvuSpin from './component/spin'
import CvuTab from './component/tab'
import CvuTable from './component/table'
import CvuTooltip from './component/tooltip'
import CvuUpload from './component/upload'

const components = {
    CvuBackTop,
    CvuButton,
    CvuButtonGroup,
    CvuCard,
    CvuCol,
    CvuCollapse,
    CvuCollapsePanel: CvuCollapse.CollapsePanel,
    CvuDivider,
    CvuDrawer,
    CvuEmpty,
    CvuLayout,
    CvuLoading,
    CvuModal,
    CvuNotification,
    CvuPaginator,
    CvuPaginatorMini,
    CvuPoptip,
    CvuPreview,
    CvuRow,
    CvuSpin,
    CvuTab,
    CvuTable,
    CvuTabPane: CvuTab.TabPane,
    CvuTooltip,
    CvuUpload
}

const Cview = {
    ...components,
    version: version
}

const install = function(Vue, opts = {}) {
    if (install.installed) {
        return
    }

    for (let key in components) {
        Vue.component(key, components[key])
    }

    //全局配置 
    Vue.prototype.$CVIEW = {
        theme: opts.theme || '',
        size: opts.size || '',
        transfer: 'transfer' in opts ? opts.transfer : ''
    }

    Vue.prototype.$cvuLoading = CvuLoading
    Vue.prototype.$cvuSpin = CvuSpin
}

Cview.install = install

if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue)
}

export default {
    install,
    ...components
}